package cn.web.management.web.servlet.account;

import cn.web.management.domain.UserState;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;

@WebServlet(name = "logoutServlet", value = "/logoutServlet")
public class logoutServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    /**
     * @description: 用户退出登录，注销其session在线状态信息
     * @paramName: [req, resp]
     * @paramType: [javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse]
     * @returnType: void
     */
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //退用户登录
        HttpSession session = req.getSession();
//        UserState userState = (UserState) session.getAttribute("userState");
        session.removeAttribute("userState");
        session.invalidate();
        resp.sendRedirect("/html/login.html");
    }
}
